package com.emm.yixun.mobile.ui.housing;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.adapter.SelectGroupAdapter;
import com.emm.yixun.mobile.adapter.SelectRommAdapter;
import com.emm.yixun.mobile.adapter.SelectUnitListAdapter;
import com.emm.yixun.mobile.adapter.SelectbuildingAdapter;
import com.emm.yixun.mobile.application.EmmApplication;
import com.emm.yixun.mobile.base.BaseActivity;
import com.emm.yixun.mobile.model.GetBuildingList;
import com.emm.yixun.mobile.model.GetPremisesList;
import com.emm.yixun.mobile.model.GetRoomList;
import com.emm.yixun.mobile.model.GetRoomList.RoomList;
import com.emm.yixun.mobile.model.GetUnitList;
import com.eroad.product.tools.MyListView;
import com.eroad.product.tools.PopuContent;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;
import xf.tools.Loading;

/**
 * <p>
 * <b>Title：</b> 意向房源
 * </p>
 * <p>
 * <b>Description：</b>
 * </p>
 *
 * @author tangxin
 * @date 2016年12月6日 下午4:05:31
 */
public class HousingresourcesActivity extends SwipeBackActivity {

    private static final String TAG = "HOUSING_RES";

    /**
     * 意向房源
     */
    TextView title_main;

    /**
     * 返回
     */
    ImageView back_btn;

    /**
     * 项目名
     */
    TextView project_name;

    /**
     * 项目ID
     */
    String project_ID;

    /**
     * 选择组团
     */
    TextView select1;

    /**
     * 组团list
     */
    MyListView want_list1;

    /**
     * 选择楼栋
     */
    TextView select2;

    /**
     * 楼栋list
     */
    MyListView want_list2;

    /**
     * 选择单元
     */
    TextView select3;

    /**
     * 单元list
     */
    MyListView want_list3;

    /**
     * 选择房号
     */
    TextView select4;

    /**
     * 房号list
     */
    MyListView want_list4;

    /**
     * 确认按钮
     */
    TextView sure_btn;

    /**
     * 组团是否选择
     */
    boolean IsSelect1 = false;

    /**
     * 楼栋是否选择
     */
    boolean IsSelect2 = false;

    /**
     * 单元是否选择
     */
    boolean IsSelect3 = false;

    /**
     * 房号是否选择
     */
    boolean IsSelect4 = false;

    boolean Isopen1 = false;

    boolean Isopen2 = false;

    boolean Isopen3 = false;

    boolean Isopen4 = false;

    private String content1;
    private String content2;
    private String content3;
    private String content4;

    private String content1ID;
    private String content2ID;
    private String content3ID;
    private String content4ID;
    private String floorType;

    /**
     * 意向房源
     */
    GetPremisesList getpremises;

    /**
     * 意向房源适配器
     */
    SelectGroupAdapter adapter;

    /**
     * 楼栋
     */
    GetBuildingList getbuilding;

    /**
     * 楼栋适配器
     */
    SelectbuildingAdapter badapter;

    /**
     * 单元
     */
    GetUnitList getunit;

    /**
     * 单元适配器
     */
    SelectUnitListAdapter unadapter;

    /**
     * 房号
     */
    GetRoomList getroom;

    /**
     * 序号适配器
     */
    SelectRommAdapter roomadapter;

    /**
     * 折扣金额
     */
    private String discountAmount = "0";

    /**
     * 折扣比例
     */
    private String discountRate = "0";

    ImageView icon_1, icon_2, icon_3, icon_4;

    boolean icon_1_boolean = false, icon_2_boolean = false, icon_3_boolean = false, icon_4_boolean = false;

    /**
     * 是否新增认筹选择房源
     */
    boolean isNewFrom = false;

    View line_group, line_buildings, line_cell, line_roomnumber;

    /**
     * 侧滑关闭框架
     */
    private SwipeBackLayout mSwipeBackLayout;

    @Override
    protected void onResume() {
        BaseActivity.activity = this; // TODO Auto-generated method stub
        super.onResume();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.housing_resources_activity);

        SetSwipeBackLayout(mSwipeBackLayout);

        BaseActivity.activity = this;

        isNewFrom = getIntent().getBooleanExtra("isNewFrom", false);
        project_ID = EmmApplication.ProjectID;

        initView();

        SetRelativiLayoutPadding(R.id.main_head_top_rela);

        initBtn();
    }

    /**
     * <p>
     * <b>Title：</b> 初始化view
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:27:47
     */
    private void initView() {
        title_main = (TextView) findViewById(R.id.title_main);

        if (isNewFrom)
            title_main.setText(getString(R.string.from_housing));
        else
            title_main.setText(getString(R.string.housing));

        back_btn = (ImageView) findViewById(R.id.back_btn);
        project_name = (TextView) findViewById(R.id.project_name);
        select1 = (TextView) findViewById(R.id.select1);
        select2 = (TextView) findViewById(R.id.select2);
        select3 = (TextView) findViewById(R.id.select3);
        select4 = (TextView) findViewById(R.id.select4);
        want_list1 = (MyListView) findViewById(R.id.want_list1);
        want_list2 = (MyListView) findViewById(R.id.want_list2);
        want_list3 = (MyListView) findViewById(R.id.want_list3);
        want_list4 = (MyListView) findViewById(R.id.want_list4);
        sure_btn = (TextView) findViewById(R.id.sure_btnd);
        icon_1 = (ImageView) findViewById(R.id.icon_1);
        icon_2 = (ImageView) findViewById(R.id.icon_2);
        icon_3 = (ImageView) findViewById(R.id.icon_3);
        icon_4 = (ImageView) findViewById(R.id.icon_4);
        line_group = findViewById(R.id.line_group);
        line_buildings = findViewById(R.id.line_buildings);
        line_cell = findViewById(R.id.line_cell);
        line_roomnumber = findViewById(R.id.line_roomnumber);
    }

    /**
     * <p>
     * <b>Title：</b> 初始化监听事件
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:28:30
     */
    private void initBtn() {
        back_btn.setVisibility(View.VISIBLE);
        back_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        project_name.setText(EmmApplication.getData(EmmApplication.ProjectName_content));// 项目名

        select1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Isopen1) {
                    Isopen1 = false;
                    icon_1.setImageResource(R.drawable.right_arrow);
                    want_list1.setVisibility(View.GONE);
                    line_group.setVisibility(View.GONE);
                } else {
                    icon_1.setImageResource(R.drawable.right_arrow22);
                    want_list1.setVisibility(View.VISIBLE);
                    line_group.setVisibility(View.VISIBLE);
                    getPremisesList();
                    Isopen1 = true;
                }
            }
        });

        want_list1.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                content1 = getpremises.getPremisesList().get(position).getPremisesName();
                content1ID = getpremises.getPremisesList().get(position).getPremisesId();
                IsSelect1 = true;
                IsSelect2 = false;
                IsSelect3 = false;
                IsSelect4 = false;
                Isopen1 = false;
                icon_1.setImageResource(R.drawable.right_arrow);
                Isopen2 = true;
                icon_2.setImageResource(R.drawable.right_arrow22);
                Isopen3 = false;
                icon_3.setImageResource(R.drawable.right_arrow);
                Isopen4 = false;
                icon_4.setImageResource(R.drawable.right_arrow);
                line_group.setVisibility(View.GONE);
                want_list1.setVisibility(View.GONE);
                want_list2.setVisibility(View.VISIBLE);
                line_buildings.setVisibility(View.VISIBLE);
                want_list3.setVisibility(View.GONE);
                line_cell.setVisibility(View.GONE);
                want_list4.setVisibility(View.GONE);
                line_roomnumber.setVisibility(View.GONE);

                select2.setText("选择楼栋");
                select3.setText("选择单元");
                select4.setText("选择房号");

                select1.setText(content1);

                getBuildingList(content1ID);
            }
        });

        want_list2.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                content2 = getbuilding.getBuildingList().get(position).getBuildingName();
                content2ID = getbuilding.getBuildingList().get(position).getBuildingId();
                IsSelect2 = true;
                IsSelect3 = false;
                IsSelect4 = false;
                Isopen1 = false;
                icon_1.setImageResource(R.drawable.right_arrow);
                Isopen2 = false;
                icon_2.setImageResource(R.drawable.right_arrow);
                Isopen3 = true;
                icon_3.setImageResource(R.drawable.right_arrow22);
                Isopen4 = false;
                icon_4.setImageResource(R.drawable.right_arrow);
                want_list1.setVisibility(View.GONE);
                line_group.setVisibility(View.GONE);
                want_list2.setVisibility(View.GONE);
                line_buildings.setVisibility(View.GONE);
                want_list3.setVisibility(View.VISIBLE);
                line_cell.setVisibility(View.VISIBLE);
                want_list4.setVisibility(View.GONE);
                line_roomnumber.setVisibility(View.GONE);

                select3.setText("选择单元");
                select4.setText("选择房号");
                select2.setText(content2);
                getUnitList(content2ID, "");
            }
        });

        want_list3.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                content3 = getunit.getUnitList().get(position).getUnitName();
                content3ID = getunit.getUnitList().get(position).getUnitId();
                IsSelect3 = true;
                IsSelect4 = false;

                Isopen1 = false;
                icon_1.setImageResource(R.drawable.right_arrow);
                Isopen2 = false;
                icon_2.setImageResource(R.drawable.right_arrow);
                Isopen3 = false;
                icon_3.setImageResource(R.drawable.right_arrow);
                Isopen4 = true;
                icon_4.setImageResource(R.drawable.right_arrow22);
                want_list1.setVisibility(View.GONE);
                line_group.setVisibility(View.GONE);
                want_list2.setVisibility(View.GONE);
                line_buildings.setVisibility(View.GONE);
                want_list3.setVisibility(View.GONE);
                line_cell.setVisibility(View.GONE);
                want_list4.setVisibility(View.VISIBLE);
                line_roomnumber.setVisibility(View.VISIBLE);
                select4.setText("选择房号");
                select3.setText(content3);

                getRoomList(content3ID, "", "");
            }
        });

        want_list4.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                content4 = getroom.getRoomList().get(position).getRoomName();
                content4ID = getroom.getRoomList().get(position).getRoomId();
                floorType = getroom.getRoomList().get(position).getFloorType();
                EmmApplication.room = getroom.getRoomList().get(position);
                discountAmount = getroom.getRoomList().get(position).getDiscountAmount();
                discountRate = getroom.getRoomList().get(position).getDiscountRate();
                IsSelect4 = true;
                Isopen1 = false;
                icon_1.setImageResource(R.drawable.right_arrow);
                Isopen2 = false;
                icon_2.setImageResource(R.drawable.right_arrow);
                Isopen3 = false;
                icon_3.setImageResource(R.drawable.right_arrow);
                Isopen4 = false;
                icon_4.setImageResource(R.drawable.right_arrow);
                want_list1.setVisibility(View.GONE);
                line_group.setVisibility(View.GONE);
                want_list2.setVisibility(View.GONE);
                line_buildings.setVisibility(View.GONE);
                want_list3.setVisibility(View.GONE);
                line_cell.setVisibility(View.GONE);
                want_list4.setVisibility(View.GONE);
                line_roomnumber.setVisibility(View.GONE);
                select4.setText(content4);
            }
        });

        select2.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (IsSelect1) {
                    if (Isopen2) {
                        Isopen2 = false;
                        icon_2.setImageResource(R.drawable.right_arrow);
                        want_list2.setVisibility(View.GONE);
                        line_buildings.setVisibility(View.GONE);
                    } else {
                        Isopen2 = true;
                        icon_2.setImageResource(R.drawable.right_arrow22);
                        want_list2.setVisibility(View.VISIBLE);
                        line_buildings.setVisibility(View.VISIBLE);

                    }
                } else {
                    EmmApplication.T("请先选择组团");
                }

            }
        });
        select3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (IsSelect2) {
                    if (Isopen3) {
                        Isopen3 = false;
                        icon_3.setImageResource(R.drawable.right_arrow);
                        want_list3.setVisibility(View.GONE);
                        line_cell.setVisibility(View.GONE);
                    } else {
                        Isopen3 = true;
                        icon_3.setImageResource(R.drawable.right_arrow22);
                        want_list3.setVisibility(View.VISIBLE);
                        line_cell.setVisibility(View.VISIBLE);
                    }
                } else {
                    EmmApplication.T("请先选择楼栋");
                }
            }
        });
        select4.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (IsSelect3) {
                    if (Isopen4) {
                        Isopen4 = false;
                        icon_4.setImageResource(R.drawable.right_arrow);
                        want_list4.setVisibility(View.GONE);
                        line_roomnumber.setVisibility(View.GONE);
                    } else {
                        Isopen4 = true;
                        icon_4.setImageResource(R.drawable.right_arrow22);
                        want_list4.setVisibility(View.VISIBLE);
                        line_roomnumber.setVisibility(View.VISIBLE);
                    }
                } else {
                    EmmApplication.T("请先选择单元");
                }
            }
        });
        sure_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.w("意向房源", content1 + "-" + content2 + "-" + content3 + "-" + content4 + "-ID:" + content4ID);
                if (select1.getText().toString().equals("选择组团")) {
                    EmmApplication.T("请选择组团");
                } else if (select2.getText().toString().equals("选择楼栋")) {
                    EmmApplication.T("请选择楼栋");
                } else if (select3.getText().toString().equals("选择单元")) {
                    EmmApplication.T("请选择单元");
                } else if (select4.getText().toString().equals("选择房号")) {
                    EmmApplication.T("请选择房号");
                } else {
                    if (EmmApplication.IsGet) {
                        EmmApplication.housinglist.clear();
                    }
                    RoomList b = new RoomList();
                    b.setRoomId(content4ID);
                    b.setRoomName(content1 + "-" + content2 + "-" + content3 + "-" + content4);// +
                    b.setFloorType(floorType);
                    b.setDiscountAmount(discountAmount);
                    if (null == discountRate || "null".equals(discountRate) || "".equals(discountRate)) {
                        discountRate = "0";
                    }
                    if ("0".equals(floorType)) {
                        b.setDiscountRate(EmmApplication.drop2("" + discountRate));
                    } else {
                        try {
                            b.setDiscountRate(EmmApplication.drop2("" + (Double.valueOf(discountRate) * 100)));
                        } catch (NullPointerException e) {
                            b.setDiscountRate("0");
                        }
                    }
                    EmmApplication.IsNewSelect = true;
                    EmmApplication.housinglist.add(b);
                    finish();
                }
            }
        });
    }

    /**
     * <p>
     * <b>Title：</b> 意向组团列表查询接口
     * </p>
     * <p>
     * <b>Description：</b>
     * </p>
     *
     * @author tangxin
     * @date 2016年12月7日 下午3:28:50
     */
    private void getPremisesList() {
        EmmApplication.updateUrl("getPremisesList");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getPremisesList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.showDialogForLoading(HousingresourcesActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                getpremises = JSONObject.parseObject(resData.toString(), GetPremisesList.class);

                if ("1".equals(getpremises.getResult())) {
                    Log.v("获取成功", "");
                    if (getpremises.getPremisesList() != null) {
                        line_group.setVisibility(View.VISIBLE);
                        adapter = new SelectGroupAdapter(HousingresourcesActivity.this, getpremises.getPremisesList());
                        want_list1.setAdapter(adapter);
                    } else {
                        line_group.setVisibility(View.GONE);
                        icon_1.setImageResource(R.drawable.right_arrow);
                        // EmmApplication.T("列表内容为空");
                        // 触发下一个列表
                        content1 = "无";
                        content1ID = "无";
                        IsSelect1 = true;
                        IsSelect2 = false;
                        IsSelect3 = false;
                        IsSelect4 = false;
                        Isopen1 = false;
                        icon_1.setImageResource(R.drawable.right_arrow);
                        Isopen2 = true;
                        icon_2.setImageResource(R.drawable.right_arrow22);
                        Isopen3 = false;
                        icon_3.setImageResource(R.drawable.right_arrow);
                        Isopen4 = false;
                        icon_4.setImageResource(R.drawable.right_arrow);
                        want_list1.setVisibility(View.GONE);
                        want_list2.setVisibility(View.VISIBLE);
                        line_buildings.setVisibility(View.VISIBLE);
                        want_list3.setVisibility(View.GONE);
                        line_cell.setVisibility(View.GONE);
                        want_list4.setVisibility(View.GONE);
                        line_roomnumber.setVisibility(View.GONE);

                        select2.setText("选择楼栋");
                        select3.setText("选择单元");
                        select4.setText("选择房号");

                        select1.setText(content1);

                        getBuildingList("");
                    }
                } else {
                    Log.v("获取失败", "errorCode:" + getpremises.getErrorCode().toString() + "errorMsg:" + getpremises.getErrorMsg().toString());
                }
            }
        });
    }

    /**
     * <p><b>Title：</b> 楼栋列表查询接口</p>
     * <p><b>Description：</b> </p>
     *
     * @param premisesId
     * @author tangxin
     * @date 2016年12月7日 下午3:29:17
     */
    private void getBuildingList(final String premisesId) {
        EmmApplication.updateUrl("getBuildingList");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("premisesId", premisesId);
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getBuildingList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.showDialogForLoading(HousingresourcesActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                getbuilding = JSONObject.parseObject(resData.toString(), GetBuildingList.class);

                if ("1".equals(getbuilding.getResult())) {
                    Log.v("获取成功", "");
                    if (getbuilding.getBuildingList() != null) {
                        badapter = new SelectbuildingAdapter(HousingresourcesActivity.this, getbuilding.getBuildingList());
                        want_list2.setAdapter(badapter);
                        line_buildings.setVisibility(View.VISIBLE);
                    } else {
                        icon_2.setImageResource(R.drawable.right_arrow);
                        // EmmApplication.T("列表内容为空");
                        content2 = "无";
                        content2ID = "无";
                        IsSelect2 = true;
                        IsSelect3 = false;
                        IsSelect4 = false;
                        Isopen1 = false;
                        icon_1.setImageResource(R.drawable.right_arrow);
                        Isopen2 = false;
                        icon_2.setImageResource(R.drawable.right_arrow);
                        Isopen3 = true;
                        icon_3.setImageResource(R.drawable.right_arrow22);
                        Isopen4 = false;
                        icon_4.setImageResource(R.drawable.right_arrow);
                        want_list1.setVisibility(View.GONE);
                        line_group.setVisibility(View.GONE);
                        want_list2.setVisibility(View.GONE);
                        line_buildings.setVisibility(View.GONE);
                        want_list3.setVisibility(View.VISIBLE);
                        line_cell.setVisibility(View.VISIBLE);
                        want_list4.setVisibility(View.GONE);
                        line_roomnumber.setVisibility(View.GONE);

                        select3.setText("选择单元");
                        select4.setText("选择房号");
                        select2.setText(content2);
                        getUnitList("", premisesId);

                    }
                } else {
                    EmmApplication.T(getbuilding.getErrorMsg().toString());
                    Log.v("获取失败", "errorCode:" + getbuilding.getErrorCode().toString() + "errorMsg:" + getbuilding.getErrorMsg().toString());
                }
            }
        });
    }

    /**
     * <p><b>Title：</b> 单元列表查询接口</p>
     * <p><b>Description：</b> </p>
     *
     * @param buildingId
     * @param premisesId
     * @author tangxin
     * @date 2016年12月7日 下午3:30:19
     */
    private void getUnitList(final String buildingId, final String premisesId) {
        EmmApplication.updateUrl("getUnitList");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("premisesId", premisesId);
        map.put("userId", EmmApplication.getUserId());
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("buildingId", buildingId);
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getUnitList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.showDialogForLoading(HousingresourcesActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                Log.v(TAG, "content:" + content);
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                getunit = JSONObject.parseObject(resData.toString(), GetUnitList.class);

                if ("1".equals(getunit.getResult())) {
                    Log.v("获取成功", "");
                    if (getunit.getUnitList() != null) {
                        unadapter = new SelectUnitListAdapter(HousingresourcesActivity.this, getunit.getUnitList());
                        want_list3.setAdapter(unadapter);
                        line_cell.setVisibility(View.VISIBLE);
                    } else {
                        // EmmApplication.T("列表内容为空");
                        line_cell.setVisibility(View.GONE);
                        icon_3.setImageResource(R.drawable.right_arrow);
                        content3 = "无";
                        content3ID = "无";
                        IsSelect3 = true;
                        IsSelect4 = false;

                        Isopen1 = false;
                        icon_1.setImageResource(R.drawable.right_arrow);
                        Isopen2 = false;
                        icon_2.setImageResource(R.drawable.right_arrow);
                        Isopen3 = false;
                        icon_3.setImageResource(R.drawable.right_arrow);
                        Isopen4 = true;
                        icon_4.setImageResource(R.drawable.right_arrow22);
                        want_list1.setVisibility(View.GONE);
                        line_group.setVisibility(View.GONE);
                        want_list2.setVisibility(View.GONE);
                        line_buildings.setVisibility(View.GONE);
                        want_list3.setVisibility(View.GONE);
                        want_list4.setVisibility(View.VISIBLE);
                        line_roomnumber.setVisibility(View.VISIBLE);

                        select4.setText("选择房号");
                        select3.setText(content3);

                        getRoomList("", buildingId, premisesId);
                    }
                } else {
                    EmmApplication.T(getunit.getErrorMsg().toString());
                    Log.v("获取失败", "errorCode:" + getunit.getErrorCode().toString() + "errorMsg:" + getunit.getErrorMsg().toString());
                }
            }
        });
    }

    /**
     * <p><b>Title：</b> 房号列表查询接口</p>
     * <p><b>Description：</b> </p>
     *
     * @param unitId
     * @param buildingId
     * @param premisesId
     * @author tangxin
     * @date 2016年12月7日 下午3:30:28
     */
    private void getRoomList(String unitId, String buildingId, String premisesId) {
        EmmApplication.updateUrl("getRoomList");
        Map<String, String> map = new HashMap<String, String>();
        map.put("version", EmmApplication.getPackageManager(5));
        map.put("merchantId", EmmApplication.getData(EmmApplication.merchantId));
        map.put("token", EmmApplication.getToken());
        map.put("userId", EmmApplication.getUserId());
        map.put("buildingId", buildingId);
        map.put("premisesId", premisesId);
        map.put("projectCode", EmmApplication.getProjectCode());
        map.put("terminalCode", EmmApplication.getPackageManager(2));
        map.put("unitId", unitId);
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("params", map);
        JSONObject json = new JSONObject(paramsMap);
        String jsonstr = json.toString();
        RequestParams params = new RequestParams();
        params.put("body", jsonstr);
        Log.v("getRoomList-->post", EmmApplication.urlStr + "?body=" + jsonstr);
        AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
        asyncHttpClient.post(EmmApplication.urlStr, params, new AsyncHttpResponseHandler() {
            @Override
            public void onFailure(Throwable error, String content) {
                super.onFailure(error, content);
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束error:" + error + "==" + content);
            }

            @Override
            public void onFinish() {
                Loading.hideDialogForLoading();
                Log.v(TAG, "请求结束");
                super.onFinish();
            }

            @Override
            public void onStart() {
                super.onStart();
                Loading.showDialogForLoading(HousingresourcesActivity.this, "正在加载...", false, true, 60000);
                Log.v(TAG, "请求开始");
            }

            @Override
            public void onSuccess(String content) {
                super.onSuccess(content);
                if (content == null) {
                    return;
                }
                JSONObject jsonObj = JSONObject.parseObject(content);
                JSONObject resData = (JSONObject) jsonObj.get("resData");
                if (resData == null) {
                    Log.v(TAG, "信息返回值为空");
                    return;
                }

                getroom = JSONObject.parseObject(resData.toString(), GetRoomList.class);

                if ("1".equals(getroom.getResult())) {
                    Log.v("获取成功", "");
                    if (getroom.getRoomList() != null) {
                        roomadapter = new SelectRommAdapter(HousingresourcesActivity.this, getroom.getRoomList());
                        want_list4.setAdapter(roomadapter);
                        line_roomnumber.setVisibility(View.VISIBLE);
                    } else {
                        line_roomnumber.setVisibility(View.GONE);
                        icon_4.setImageResource(R.drawable.right_arrow);
                        PopuContent.poPu(HousingresourcesActivity.this, "房号列表为空", false, 1);
                        // EmmApplication.T("列表内容为空");
                        ArrayList<RoomList> mList = new ArrayList<GetRoomList.RoomList>();
                        if (null == roomadapter) {
                            roomadapter = new SelectRommAdapter(HousingresourcesActivity.this, mList);
                            want_list4.setAdapter(roomadapter);
                        } else {
                            roomadapter.GetDate(mList);
                        }
                    }
                } else {
                    EmmApplication.T(getroom.getErrorMsg().toString());
                    Log.v("获取失败", "errorCode:" + getroom.getErrorCode().toString() + "errorMsg:" + getroom.getErrorMsg().toString());
                }
            }
        });
    }

}
